package com.rfsp.mcp.service;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rfsp.common.base.BaseService;
import com.rfsp.common.base.ResultVO;
import com.rfsp.common.shiro.ShiroUtils;
import com.rfsp.mcp.mapper.ContactMapper;
import com.rfsp.common.mapper.OrgMapper;
import com.rfsp.mcp.pojo.po.ContactPO;
import com.rfsp.common.pojo.po.OrgPO;
import com.rfsp.common.pojo.po.UserPO;

@Service
public class ContactService extends BaseService<ContactPO> {

	public Logger log = LoggerFactory.getLogger(ContactService.class);
	
	@Autowired
	ContactMapper mapper;
	
	@Autowired
	OrgMapper orgMapper;
	
	public String updateContactMsg(String status) throws Exception{
		UserPO user = ShiroUtils.getAttribute("user");
		OrgPO org = ShiroUtils.getAttribute("org");
		ContactPO coq = new ContactPO();
		coq.setRootUser(user.getCreator());
		coq.setCreator(user.getUserCode());
		coq.setContact(org.getContactName());
		List<ContactPO> list = mapper.select(coq);
		if(null==list) {
			return ResultVO.FAIL;
		}else {
			ContactPO single = list.get(0);
			single.setStatus(status);
			mapper.updateByPrimaryKeySelective(single);
			return ResultVO.SUCCESS;
		}	
	}
	
	
	public List<ContactPO> queryContactByCreator(String userCode) {
		ContactPO formIn = new ContactPO();
		formIn.setCreator(userCode);
		formIn.setStatus("1");
		return mapper.select(formIn);
	}
	
	public List<ContactPO> queryContactByRootUser(String rootUserCode) {
		ContactPO formIn = new ContactPO();
		formIn.setRootUser(rootUserCode);
		return mapper.select(formIn);
	}
}
